import 'package:appflutterhomeschool/model/tab_model.dart';
import 'package:appflutterhomeschool/res/styles.dart';
import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';

///用户： ninetailedfox
///时间： 2020/6/16
///邮箱： 1037438704@qq.com
///功能： 通知页面顶部的Tab
class NoticeTabWidget extends StatelessWidget {
  final List<TabModel> listTab;
  final ValueChanged<int> getIndex;

  final GestureTapCallback unreadBoolOnTap;
  final bool openScreen, unreadBool,rightUnread;

  NoticeTabWidget(
      {this.listTab,
      this.getIndex,
      this.rightUnread,
      this.openScreen,
      this.unreadBool,
      this.unreadBoolOnTap});

  @override
  Widget build(BuildContext context) {
    return Visibility(
      visible: openScreen??false,
      child: Container(
        color: Colors.white,
        height: ScreenUtil().setWidth(115),
        child: Row(
          children: <Widget>[
            ListView.builder(
                scrollDirection: Axis.horizontal,
                physics: NeverScrollableScrollPhysics(),
                shrinkWrap: true,
                itemCount: listTab.length,
                itemBuilder: _widget),
            Expanded(child: Container()),
            Visibility(
              visible: rightUnread??false,
              child: GestureDetector(
                onTap: unreadBoolOnTap,
                child: Row(
                  children: <Widget>[
                    Container(
                      alignment: Alignment.center,
                      margin: EdgeInsets.only(right: 5),
                      child: Icon(
                        !(unreadBool??false)
                            ? Icons.radio_button_unchecked
                            : Icons.check_circle,
                        size: 15,
                        color: !(unreadBool??false) ? Colors.grey : Colors.blue,
                      ),
                    ),
                    Container(
                      margin: EdgeInsets.only(right: ScreenUtil().setWidth(35)),
                      child: Text(
                        (unreadBool??false) ? "已读" : "未读",
                        style: TextStyles.textDark37,
                      ),
                    ),
                  ],
                ),
              ),
            ),
          ],
        ),
      ),
    );
  }

  Widget _widget(BuildContext context, int index) {
    return GestureDetector(
      onTap: () {
        getIndex(index);
      },
      child: Column(
        children: <Widget>[
          Expanded(
              child: Container(
            padding: EdgeInsets.only(
                left: ScreenUtil().setWidth(37),
                right: ScreenUtil().setWidth(37)),
            alignment: Alignment.center,
            child: Text(
              listTab[index].titleTab,
              style: listTab[index].display
                  ? TextStyles.textDark37
                  : TextStyles.textGray37,
            ),
          )),
          Visibility(
            visible: listTab[index].display,
            child: Container(
              width: ScreenUtil().setWidth(70),
              color: Colors.blue,
              height: 4,
            ),
          )
        ],
      ),
    );
  }
}
